package com.cloudkinto.appletController.orderinput;


import com.cloudkinto.appletservice.orderinput.AppletOrderInputService;
import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.orderinput.OrderInputService;
import com.cloudkinto.service.orderinput.vo.OrderInputAddReq;
import com.cloudkinto.service.orderinput.vo.OrderInputUpdateReq;
import com.cloudkinto.service.product.ProductInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 张永远
 * @since 2020-06-08
 */
@RestController
@Api(tags = "小程序订单入库模块")
@RequestMapping("/api/applet/orderInput")
public class AppletOrderInputController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(AppletOrderInputController.class);

    @Autowired
    private AppletOrderInputService service;


    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查看详情", notes = "根据id查看详情")
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", service.detail(id));
    }

    @UserSessionRequired
    @GetMapping("/pageInit")
    @ApiOperation(value = "查询初始化", notes = "查询初始化")
    public SingleResult pageInit() {
        return service.pageInit(getCurrentUserId(), getCompanyId());
    }

    @UserSessionRequired
    @GetMapping("/listPage")
    @ApiOperation(value = "查询（分页）", notes = "查询（分页）")
    public PageResult listPage(HttpServletRequest request) {
        Long companyId = getCompanyId();

        Map<String, String> map = new HashMap<>();
        String status = request.getParameter("status");
        String shopId = request.getParameter("shopId");
        String keyword = request.getParameter("keyword");
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        map.put("companyId", companyId + "");
        map.put("status", status);
        if (getShopId() != null)
            shopId = String.valueOf(getShopId());
        map.put("shopId", shopId);
        map.put("keyword", keyword);
        map.put("current", current);
        map.put("pageSize", size);
        return service.getListPage(map);
    }


}

